package com.sgl.retrofitdemo.ui.business.main;

import android.util.Log;

import com.sgl.retrofitdemo.net.entity.request.UserInfo;
import com.sgl.retrofitdemo.net.entity.respons.UserInfoEntity;
import com.sgl.retrofitdemo.net.interactor.UserInfoGetUseCase;
import com.sgl.retrofitdemo.net.interactor.UserInfoPostUseCase;
import com.sgl.retrofitdemo.ui.base.DefaultErrorSubscriber;

/**
 * Created by sunqiyong on 2016/11/13.
 */

public class MainPresenter implements MainContract.Presenter {
    private UserInfoGetUseCase mUserInfoGetUseCase;
    private UserInfoPostUseCase mUserInfoPostUseCase;
    private MainContract.MainView mMainView;

    public MainPresenter(MainContract.MainView mMainView) {
        this.mMainView = mMainView;
        this.mUserInfoGetUseCase = new UserInfoGetUseCase();
        this.mUserInfoPostUseCase = new UserInfoPostUseCase();
    }

    @Override
    public void testPost(UserInfo userInfo) {
        mUserInfoPostUseCase.setmUserInfo(userInfo);
        mUserInfoPostUseCase.subscribe(new DefaultErrorSubscriber<UserInfoEntity>(){
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mMainView.setResult("post : error");
            }

            @Override
            public void onCompleted() {
                super.onCompleted();
                mMainView.setResult("post : onCompleted");
            }

            @Override
            public void onNext(UserInfoEntity userInfoEntity) {
                super.onNext(userInfoEntity);
                mMainView.setData(userInfoEntity);
                mMainView.setResult("post : onNext");
            }
        });
    }

    @Override
    public void testGet(String count, String password) {
        mUserInfoGetUseCase.setmCount(count);
        mUserInfoGetUseCase.setmPassWord(password);
        mUserInfoGetUseCase.subscribe(new DefaultErrorSubscriber<UserInfoEntity>(){
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                Log.e("qwer","");
                mMainView.setResult("get : error");
            }

            @Override
            public void onCompleted() {
                super.onCompleted();
                Log.e("qwer","");
                mMainView.setResult("get : onCompleted");
            }

            @Override
            public void onNext(UserInfoEntity userInfoEntity) {
                super.onNext(userInfoEntity);
                Log.e("qwer","");
                mMainView.setData(userInfoEntity);
                mMainView.setResult("get : onNext");
            }
        });
    }
}
